package org.example.day;

import java.util.Arrays;


/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/08/09 17:18
 */
public class Solution3132 {

    public static void main(String[] args) {
        System.out.println(new Solution3132().minimumAddedInteger(new int[]{7,9,1,4}, new int[]{0,8}));
    }

    public int minimumAddedInteger(int[] nums1, int[] nums2) {
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        int x = Integer.MAX_VALUE;
        for (int i = 0; i < 3; i++) {
            x = Math.min(x, findMin(i, nums1, nums2));
            System.out.println(findMin(i, nums1, nums2));
        }
       return x;
    }

    private int findMin(int i, int[] nums1, int[] nums2) {
        int count = i;
        int x = nums2[0] - nums1[i];
        int end = 2 - i;
        for (int j = i; j < nums1.length - end; j++) {
            if(x != (nums2[j-i] - nums1[j])){
                count++;
                i++;
                end--;
            }
            if(count > 2){
                return Integer.MAX_VALUE;
            }
        }
        return x;
    }

}
